package com.xizimall.portal.service.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.xizimall.pojo.TbUser;
import com.xizimall.portal.service.UserService;
import com.xizimall.common.pojo.XizimallResult;
import com.xizimall.common.utils.HttpClientUtil;
@Service
public class UserServiceImpl implements UserService {
    
	@Value("${SSO_BASE_URL}")
	public String SSO_BASE_URL;
	
	@Value("${SSO_USER_TOKEN}")
	private String SSO_USER_TOKEN;
	
	@Value("${SSO_PAGE_LOGIN}")
	public String SSO_PAGE_LOGIN;
	
	@Override
	public TbUser getUserByToken(String token) {
		try {
			//调用sso服务
			String json = HttpClientUtil.doGet(SSO_BASE_URL+SSO_USER_TOKEN+token);
			//把json转换成xizimallresult对象
			XizimallResult result = XizimallResult.formatToPojo(json, TbUser.class);
			if(result.getStatus()==200){
				TbUser user = (TbUser) result.getData();
				return user;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
